-
Notifications
You must be signed in to change notification settings - Fork 533
Experimental: PINT module bindings. #937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Gadgetoid
wants to merge
6
commits into
main
Choose a base branch
from
feature/pint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cc7a169
to
d256b9e
Compare
Quickstart for the reference implementation: import network
import socket
class PINT_Socket:
"""An arbitrary structure for storing data about your sockets.
Does not have to be a class, you could just return an int with the
socket ID of your target device.
"""
def __init__(self):
pass
class PINT_NIC:
"""The actual NIC implementation.
Most of the heavy lifting is sockets based, you might want to implement
the socket_ methods on your socket class and simply delegate to them.
"""
def __init__(self) -> None:
pass
def __del__(self) -> None:
pass
def gethostbyname(self, name: str) -> tuple[int, int, int, int]:
return (127, 0, 0, 1)
def socket_socket(self) -> PINT_Socket:
return PINT_Socket()
def socket_close(self, socket: PINT_Socket) -> None:
pass
def socket_bind(self, socket: PINT_Socket, ip: tuple[int, int, int, int], port: int) -> bool:
return True
def socket_listen(self, socket: PINT_Socket, backlog: int) -> bool:
return True
def socket_accept(self, socket: PINT_Socket, socket2: PINT_Socket, ip: tuple[int, int, int, int], port: int) -> bool:
return True
def socket_connect(self, socket: PINT_Socket, ip: tuple[int, int, int, int], port) -> bool:
return True
def socket_send(self, socket: PINT_Socket, buf: bytearray) -> int:
return 0
def socket_recv(self, socket: PINT_Socket, buf: bytearray) -> int:
"""Buf is provided as a mutable bytearray, you must write into it."""
return 0
def socket_sendto(self, socket: PINT_Socket, buf: bytearray, ip, port) -> int:
return 0
def socket_recvfrom(self, socket: PINT_Socket, buf: bytearray, ip, port) -> int:
"""Buf is provided as a mutable bytearray, you must write into it."""
return 0
def socket_setsockopt(self, socket: PINT_Socket, level: int, opt: int, val: bytearray) -> bool:
return True
def socket_settimeout(self, socket: PINT_Socket, timeout_ms: int) -> bool:
return True
def socket_ioctl(self, socket: PINT_Socket, request: int, arg: int) -> bool:
return True
# Instance of our Python network driver
impl = PINT_NIC()
# Init PINT with our implementation
net = network.PINT(impl)
# Try some stuff
print(socket.getaddrinfo("google.com", 80)[0][-1])
test = socket.socket()
test.connect(("127.0.0.1", 80)) # this is where socket_socket is actually called
sent = test.write(b"Hello World")
result = test.read(10)
print(result) |
2dd7dca
to
0fea390
Compare
ee4e9ea
to
d84298f
Compare
TODO: Update the implementation stub above with my many, many findings from putting PINT to the test. |
8ae2df2
to
95909d5
Compare
45c67b6
to
6efa5cf
Compare
P.I.N.T Python Implementation of Network Transports.
Forward domain, type and proto to the socket binding.
6fad991
to
1597592
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
P.I.N.T
Python Implementation of Network Transports.
The goal of this module/project/drive is to create a standard network driver which binds against a Python class in order to do the heavy lifting.
Why?
MicroPython is moving toward write-everything-in-Python. Following with network drivers allows us to experiment and prototype faster, makes networking less of a black box to end users, and lets folks - in theory - do custom network drivers for fun and profit, without having to delve into the sticky particulars of building modules and binding drivers.
It's my sincere hope that MicroPython will incorporate something like this in future, rendering PINT obsolete. But for now- a POC is a good start!